package com.hightrast.service.compareToData.stage.impl;

import com.hightrast.service.api.entity.RastOrderProductItems;
import com.hightrast.service.api.enums.PaybackStatusEnum;
import com.hightrast.service.compareToData.stage.EntityUpdater;
import com.hightrast.service.util.BaseEntityUtil;

import java.util.Objects;

/**
 *  订单商品项 更新策略实现
 */
public class RastOrderProductItemUpdater implements EntityUpdater<RastOrderProductItems> {
    @Override
    public void updateEntity(RastOrderProductItems oldEntity, RastOrderProductItems newEntity) {
        if(Objects.nonNull(oldEntity.getPrimaryItemId()) && oldEntity.getPrimaryItemId() != 0){
            // 退款的商品项 更新最终价格、数量、订单状态
            oldEntity.setPreTaxPrice(newEntity.getPreTaxPrice());
            oldEntity.setQuantity(newEntity.getQuantity());
        }else {
            if(PaybackStatusEnum.Issuing.getValue().equals(oldEntity.getPaybackStatus())){
                oldEntity.setPaybackStatus(newEntity.getPaybackStatus());
            }
        }
        oldEntity.setOrderStatus(newEntity.getOrderStatus());
        BaseEntityUtil.update(oldEntity);
    }
}